import ConveyerBelt from '@/store/_conveyerBelt'
import { PageRefVar } from '@/store/_pageData'
import { ref, watch } from 'vue'

export default class ShopStore {
  // 收餐方式：外卖、堂食、自提
  public receivingMethod = new PageRefVar<string | undefined>('pages/shop/index')
  public shopId = new PageRefVar<number | undefined>('pages/shop/index')
  public seatNumber = new PageRefVar<string | undefined>('pages/shop/index')
  public inviteCode = new PageRefVar<string | undefined>('pages/shop/index')
  public isInviter = new PageRefVar<boolean | undefined>('pages/shop/index')
  public isGuest = (() => {
    const result = ref<boolean | undefined>()
    watch(
      [this.inviteCode.getRef(), this.seatNumber.getRef(), this.isInviter.getRef()],
      ([inviteCode, seatNumber, isInviter]) => {
        console.log('isGuest', inviteCode, seatNumber, isInviter, this.isInviter.getRef())
        result.value = inviteCode != null && seatNumber == null && !isInviter
      },
      { immediate: true }
    )
    return result
  })()
  // 店铺默认筛选参数传递
  public conveyerBelt = new ConveyerBelt()
}
